import java.util.ArrayList;
import java.util.HashMap;

public class Solution {
    public class RandomListNode {
        int label;
        RandomListNode next = null;
        RandomListNode random = null;

        RandomListNode(int label) {
            this.label = label;
        }
    }
    public RandomListNode Clone(RandomListNode pHead) {
        //创建一个哈希桶
        HashMap<RandomListNode,RandomListNode> map=new HashMap<>();
        //遍历链表保存到哈希桶里面
        RandomListNode cur= pHead;
        while(cur!=null){
            RandomListNode node=new RandomListNode(cur.label);
            map.put(cur,node);
            cur=cur.next;
        }
        //再一次遍历链表
        cur=pHead;
        while(cur!=null){
            map.get(cur).next=map.get(cur.next);
            map.get(cur).random=map.get(cur.random);
            cur=cur.next;
        }

        return map.get(pHead);
    }
    //顺时针打印链表
    public ArrayList<Integer> printMatrix(int [][] matrix) {
        //判断matrix 是不是weikong
        if(matrix.length==0){
            return new ArrayList<Integer>(1);
        }
        ArrayList <Integer> arr=new ArrayList<>();
        //上边界
        int up=0;
        //下边界
        int down=matrix.length-1;
        //左边界
        int left =0;
        //右 边界
        int right=matrix[0].length-1;
        while(up<=down&&left<=right){
            //打印上边界
            for(int i=left;i<=right;i++){
                arr.add(matrix[up][i]);
            }
            //上边界减
            up++;
            if(up>down){
                break;
            }
            //打印右边界
            for(int i=up;i<=down;i++){
                arr.add(matrix[i][right]);
            }
            //右边界减减
            right--;
            if(left>right){
                break;
            }
            //打印下边界
            for(int i=right;i>=left;i--){
                arr.add(matrix[down][i]);
            }
            down--;
            if(up>down){
                break;
            }
            //打印左边界
            for(int i=down;i>=up;i--){
                arr.add(matrix[i][left]);

            }
            left++;
             if(up>down){
                break;
            }
        }
      return arr;
       
    }
}